<?php
//
//-------------------------------------------------
// | CreateTime: 2020/8/24 19:33
//+------------------------------------------------
// | Author: chenxueyuan
//+------------------------------------------------
// | Describe: ...
//+------------------------------------------------

namespace app\admin\controller;

use app\admin\model\Tags as tagsModel;

class Tags extends Common
{
    public function lst(){
        $tags_mod= model('tags');
        $tas_all=$tags_mod->paginate(3);

       // $db=db('tags')->select();
        $this->assign('tags',$tas_all);
        return view();
    }

    public function add(){
        return view();
    }


    //提交处理
    public function addhanddle(){
        if($this->request->isPost()){
            $post=$this->request->post();
           // $res=db('tags')->insert($post);

            $validate= validate('Tags');
            if (!$validate->check($post)){
                $this->error($validate->getError(),'add');
            }
            $tas_model= new tagsModel();
            $tas_model_save=$tas_model->save($post);
            if ($tas_model_save){
                $this->success('成功','lst');
            }else{
                $this->error('失败','lst');
                return view();
            }

        }
    }



    public function upd($id=''){

        $tags_model=model('Tags');
        $tags_get=$tags_model->get($id);
        if(empty($tags_get)){

            $this->redirect('admin/tags/lst');
        }else{
            $this->assign('tags', $tags_get);
            return view();
        }
        $tags_model->save();
    }
    public function updhanddle(){
        if($this->request->isPost()){
            $post= $this->request->post();
            $validate= validate('Tags');
            if(!$validate->check($post)){
                $this->error($validate->getError(),'admin/tags/lst');
            }else{
                $tags_model= new \app\admin\model\Tags();
                $tags_get= $tags_model->get($post['id']);
                $result= $tags_get->save(['name'=>$post['name']]);
                if($result){
                    $this->success('更新成功','admin/tags/lst');
                }else{
                    $this->error('更新失败','admin/tags/lst');
                }
                var_dump( $tags_get);die();
            }
        }else{
            $this->redirect('admin/tags/lst');
        }
    }


}